#include <func.h>
#include <signal.h>
void handler(int signum, siginfo_t *psiginfo, void *p){
    printf("signum = %d\n", signum);
    printf("pid = %d, uid = %d\n", psiginfo->si_pid, psiginfo->si_uid);
    //判断3信号是否处于未决状态
    sigset_t pending;
    sigpending(&pending);
    if(sigismember(&pending,SIGQUIT))
    {
        printf("sigquit is pending!\n");
    }
    else{
        printf("sigquit is not pending!\n");
    }
}
int main(int argc, char *argv[])
{
    struct sigaction act;
    memset(&act,0,sizeof(act)); 
    act.sa_sigaction = handler; 
    act.sa_flags = SA_RESTART|SA_SIGINFO;

    // SA_SIGINFO 选用3参数的回调
    sigaction(SIGINT,&act,NULL);
    
    //不会被3信号打断
    sigemptyset(&act.sa_mask);
    sigaddset(&act.sa_mask,SIGQUIT);

    sigaction(SIGINT,&act,NULL);
    sigaction(SIGQUIT,&act,NULL);



    char buf[4096] = {0};
    ssize_t sret = read(STDIN_FILENO,buf,sizeof(buf));
    printf("sret = %ld, buf = %s\n", sret, buf);
    return 0;
}

